#set_thread_obselete.py
#call be store
#store set the thread obselete 

import wsgiref.handlers

from google.appengine.ext import webapp
from google.appengine.ext.webapp import template

from xmw.tianya import error_tianya
from xmw.tianya.bot import *
from xmw import counter
import xmw
from xmw import tianya

import os

class MainPage(xmw.RequestHandler):
    def get(self):
        e=None
        if  not (self.request.GET.has_key('url') ):
            e = error_tianya.ARGUMENT_FAULT("/set_thread_obselete?url=XXXXXX, while now it is %s"%str(self.request))
        else:
            #thread_id   =self.request.GET['thread_id']
            #id=thread_id.encode("ascii")
            url   =self.request.GET['url']
            q=Bot_Thread.all()
            q.filter("page_url =", url)
            q.filter("is_readed =", False)
            thread=q.get()

            if thread is None:
                e = error_tianya.THREAD_NOT_EXIST("/set_thread_obselete?url=%s, not found the FRESH thread"%str(url))
            else:
                thread.is_readed=True
                thread.put()
                e=error_tianya.OK("set thread with url=%s obselete"%(url))
        
        self.render_error(e)
        
        

def main():
  application = webapp.WSGIApplication(
                                       [('/set_thread_obselete', MainPage)],
                                       debug=True)
  wsgiref.handlers.CGIHandler().run(application)

if __name__ == "__main__":
  main()
  